import {pool} from 'workerpool'

export const useExcelTempPool = () => {

  const poolUse = pool( new URL('./excelTempWorker.js', import.meta.url).href, {
    maxWorkers: 4,
    workerType: 'web',
    workerOpts: { type: 'module' } // 关键配置
  })

  const process = async (sheetsToProcess, data, fnMap) => {
    try {
      return poolUse.exec('renderView', [sheetJsonStr, data, fnMap])
    } catch (e) {
      console.error(e)
      throw e
    } finally {
      await poolUse.terminate()
    }
  }
  return {
    process
  }
}
